package com.ruoyi.controller;


import com.ruoyi.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@Api(tags = "初步预警分级模型算法")
@RequestMapping("/warning")
@RestController
public class WarningController {

    @ApiOperation("获取电梯预警等级--1:一级预警;2:二级预警;3:三级预警;4:四级预警")
    @PostMapping("/dt")
    public Map getWarningDt(@RequestBody WarningDtDto warningDtDto) {
        Map map = new HashMap();
        map.put("number",warningDtDto.getNumber());
        String trap =warningDtDto.getTrap();
        String fxdj =warningDtDto.getFxdj();
        if("1".equals(trap)){
            if("1".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("2".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("3".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }else {
            if("1".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("2".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("3".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        return map;
    }

    @ApiOperation("获取供水管道流量监测预警分级模型")
    @PostMapping("/pipelineflow")
    public Map getWarningPipelineFlow(@RequestBody WarningPipelineFlowDto warningPipelineFlowDto) {
        Map map = new HashMap();
        map.put("number",warningPipelineFlowDto.getNumber());
        Double v =warningPipelineFlowDto.getV();
        Double v0 =warningPipelineFlowDto.getV0();
        Double v_v0 = 1.0;
        if((v!=null) && (v0!=null) && (v0!=0.0)){
            v_v0 = v/v0;
        }
        String fxdj =warningPipelineFlowDto.getFxdj();
        if(v_v0 < 0.5){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }
        }
        else if(((v_v0 >= 0.5)&&(v_v0 < 0.8))||(v_v0 > 1.5)){
            if("1".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("2".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("3".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else {
            map.put("code","5");
            map.put("name","不预警");
        }
        return map;
    }

    @ApiOperation("获取供水管道压力监测预警分级模型")
    @PostMapping("/pipelinepress")
    public Map getWarningPipelinePress(@RequestBody WarningPipelinePressDto warningPipelinePressDto) {
        Map map = new HashMap();
        map.put("number",warningPipelinePressDto.getNumber());
        Double p =warningPipelinePressDto.getP();
        Double p0 =warningPipelinePressDto.getP0();
        Double p_p0 = 1.0;
        if((p!=null) && (p0!=null) && (p0!=0.0)){
            p_p0 = p/p0;
        }
        String fxdj =warningPipelinePressDto.getFxdj();
        if(p_p0 < 0.5){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }
        }
        else if(((p_p0 >= 0.5)&&(p_p0 < 0.8))||(p_p0 > 1.5)){
            if("1".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("2".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("3".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else {
            map.put("code","5");
            map.put("name","不预警");
        }
        return map;
    }

    @ApiOperation("获取建筑物消防压力监测预警分级")
    @PostMapping("/xfpress")
    public Map getWarningXFPress(@RequestBody WarningXFPressDto warningXFPressDto) {
        Map map = new HashMap();
        map.put("number",warningXFPressDto.getNumber());

        String fxdj =warningXFPressDto.getFxdj();
        if("1".equals(fxdj)){
            map.put("code","3");
            map.put("name","三级预警");
        }else if("2".equals(fxdj)){
            map.put("code","3");
            map.put("name","三级预警");
        }else if("3".equals(fxdj)){
            map.put("code","4");
            map.put("name","四级预警");
        }else if("4".equals(fxdj)){
            map.put("code","4");
            map.put("name","四级预警");
        }else {
            map.put("code","5");
            map.put("name","不预警");
        }

        return map;
    }

    @ApiOperation("获取建筑物消防烟感监测预警分级模型")
    @PostMapping("/xfsmoke")
    public Map getWarningXFSmoke(@RequestBody WarningXFSmokeDto warningXFSmokeDto) {
        Map map = new HashMap();
        map.put("number",warningXFSmokeDto.getNumber());
        Integer d = 1;
        if(warningXFSmokeDto.getDuration()!=null && warningXFSmokeDto.getDuration() > 1){
            d = warningXFSmokeDto.getDuration();
        }

        String fxdj =warningXFSmokeDto.getFxdj();
        if(d < 10){
            map.put("code","5");
            map.put("name","不预警");
        }
        else if(d<60){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else {
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }
        }
        return map;
    }

    @ApiOperation("获取可燃气体浓度监测预警分级模型")
    @PostMapping("/gasconcentration")
    public Map getWarningXFSmoke(@RequestBody WarningGasConcentrationDto warningGasConcentrationDto) {
        Map map = new HashMap();
        map.put("number",warningGasConcentrationDto.getNumber());
        Double d = 0.9;
        if(warningGasConcentrationDto.getConcentration()!=null && warningGasConcentrationDto.getConcentration() > 1.0){
            d = warningGasConcentrationDto.getConcentration();
        }

        String fxdj =warningGasConcentrationDto.getFxdj();
        if(d <= 1.0){
            map.put("code","5");
            map.put("name","不预警");
        }
        else if(d>1.0 && d <=3.0){
            if("1".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else if(d>3.0 && d <5.0){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else {
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }
        }
        return map;
    }


    @ApiOperation("获取燃气管道压力监测预警分级模型")
    @PostMapping("/gaspress")
    public Map getWarningGasPress(@RequestBody WarningGasPressDto warningGasPressDto) {
        Map map = new HashMap();
        map.put("number",warningGasPressDto.getNumber());
        Double p =warningGasPressDto.getP();
        Double p0 =warningGasPressDto.getP0();
        Double p_p0 = 0.4;
        if((p!=null) && (p0!=null) && (p0!=0.0)){
            p_p0 = p/p0;
        }
        String fxdj =warningGasPressDto.getFxdj();
        if(p_p0 < 0.5){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }
        }
        else if((p_p0 >= 0.5)&&(p_p0 < 0.8)){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else {
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        return map;
    }


    @ApiOperation("获取热力管道温度监测预警分级模型")
    @PostMapping("/rltemperature")
    public Map getWarningRLtemperature(@RequestBody WarningRLTemperatureDto warningRLTemperatureDto) {
        Map map = new HashMap();
        map.put("number",warningRLTemperatureDto.getNumber());
        Double p =warningRLTemperatureDto.getT();
        Double p0 =warningRLTemperatureDto.getT0();
        Double p_p0 = 0.7;
        if((p!=null) && (p0!=null) && (p0!=0.0)){
            p_p0 = p/p0;
        }
        String fxdj =warningRLTemperatureDto.getFxdj();
        if(p_p0 < 0.8){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }
        }
        else if((p_p0 >= 0.8)&&(p_p0 < 0.9)){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else {
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        return map;
    }


    @ApiOperation("获取危化品运输车辆监测预警分级")
    @PostMapping("/chemicals")
    public Map getWarningChemicals(@RequestBody WarningChemicalsDto warningChemicalsDto) {
        Map map = new HashMap();
        map.put("number",warningChemicalsDto.getNumber());
        String leak =warningChemicalsDto.getLeak();

        String fxdj =warningChemicalsDto.getFxdj();
        if(leak != null && "1".equals(leak)){
            if("1".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(fxdj)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }
        }
        else {
            if("1".equals(fxdj)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("2".equals(fxdj)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("3".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }else if("4".equals(fxdj)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        return map;
    }

    @ApiOperation("燃气浓度预警模型")
    @PostMapping("/gas/density")
    public Map getWarningChemicals(@RequestBody WarningGasDensityDto warningGasDensityDto) {
        Map map = new HashMap();
        map.put("number",warningGasDensityDto.getNumber());
        map.put("input",warningGasDensityDto);
        String alarmLevel =warningGasDensityDto.getAlarmLevel();
        String riskLevel =warningGasDensityDto.getRiskLevel();
        if(alarmLevel==null || riskLevel ==null)
        {
            map.put("msg","请输入正确的参数");
            return map;
        }
        if(alarmLevel != null && "1".equals(alarmLevel)){
            if("1".equals(riskLevel)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(riskLevel)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("3".equals(riskLevel)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("4".equals(riskLevel)){
                map.put("code","2");
                map.put("name","二级预警");
            }
        }
        else if(alarmLevel != null && "2".equals(alarmLevel)){
            if("1".equals(riskLevel)){
                map.put("code","1");
                map.put("name","一级预警");
            }else if("2".equals(riskLevel)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("3".equals(riskLevel)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("4".equals(riskLevel)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else if(alarmLevel != null && "3".equals(alarmLevel)){
            if("1".equals(riskLevel)){
                map.put("code","2");
                map.put("name","二级预警");
            }else if("2".equals(riskLevel)){
                map.put("code","3");
                map.put("name","三级预警");
            }else if("3".equals(riskLevel)){
                map.put("code","4");
                map.put("name","四级预警");
            }else if("4".equals(riskLevel)){
                map.put("code","4");
                map.put("name","四级预警");
            }
        }
        else {
            map.put("msg","请输入正确的参数");
        }
        return map;
    }
    @ApiOperation("燃气压力预警模型")
    @PostMapping("/gas/pressure")
    public Map getWarningGasPresure(@RequestBody WarningGasPressureDto warningGasPressureDto) {
        Map map = new HashMap();
        map.put("number",warningGasPressureDto.getNumber());
        map.put("input",warningGasPressureDto);
        Double P =warningGasPressureDto.getP();
        Double P0 =warningGasPressureDto.getP0();
        Double ratio = 0.0;
        if(P==null || P0 == null || P0==0)
        {
            map.put("msg","请输入正确的参数");
            return map;
        }
        ratio = P/P0;
        if(ratio >= 0.8)
        {
            map.put("level","三级预警");
        }
        else if(ratio >= 0.5)
        {
            map.put("level","二级预警");
        }
        else
        {
            map.put("level","一级预警");
        }
        return map;
    }

    @ApiOperation("交通类预警分级模型")
    @PostMapping("/jt/alarm")
    public Map getJtAlarm(@RequestBody WarningJtAlarmDto warningJtAlarmDto) {
        Map map = new HashMap();
        map.put("number",warningJtAlarmDto.getNumber());
        map.put("input",warningJtAlarmDto);
        Integer days =warningJtAlarmDto.getFiveDayTimes();
        Double duration = 0.0;
        if(warningJtAlarmDto.getDuration()!=null)
        {
            duration = warningJtAlarmDto.getDuration();
        }

        if(days == null)
        {
            map.put("msg","请输入正确的参数");
            return map;
        }

        if(days >= 10)
        {
            map.put("level","一级预警");
        }
        else if(days >= 5)
        {
            if(duration<2.0){
                map.put("level","二级预警");
            }
            else {
                map.put("level","一级预警");
            }
        }
        else if(days >= 2)
        {
            if(duration<2.0){
                map.put("level","三级预警");
            }
            else {
                map.put("level","二级预警");
            }
        }
        else
        {
            if(duration<2.0){
                map.put("level","四级预警");
            }
            else {
                map.put("level","三级预警");
            }

        }
        return map;
    }



    @ApiOperation("消防预警分级模型-火警")
    @PostMapping("/xf/fireAlam")
    public Map getXfAlert(@RequestBody WarningXfAlarmDto warningXfAlertDto) {
        Map map = new HashMap();
        map.put("number",warningXfAlertDto.getNumber());
        map.put("input",warningXfAlertDto);
        map.put("level","一级预警");
        return map;
    }

    @ApiOperation("消防预警分级模型-水压")
    @PostMapping("/xf/waterAlarm")
    public Map getJtAlarm(@RequestBody WarningXfWaterAlarmDto warningXfWaterAlarmDto) {
        Map map = new HashMap();
        map.put("number",warningXfWaterAlarmDto.getNumber());
        map.put("input",warningXfWaterAlarmDto);
        Integer days =warningXfWaterAlarmDto.getSevenDayTimes();
        Double duration = 0.0;
        if(warningXfWaterAlarmDto.getDuration()!=null)
        {
            duration = warningXfWaterAlarmDto.getDuration();
        }

        if(days == null)
        {
            map.put("msg","请输入正确的参数");
            return map;
        }

        if(days >= 10)
        {
            map.put("level","一级预警");
        }
        else if(days >= 5)
        {
            if(duration<5.0){
                map.put("level","二级预警");
            }
            else {
                map.put("level","一级预警");
            }
        }
        else if(days >= 2)
        {
            if(duration<5.0){
                map.put("level","三级预警");
            }
            else {
                map.put("level","二级预警");
            }
        }
        else
        {
            if(duration<5.0){
                map.put("level","四级预警");
            }
            else {
                map.put("level","三级预警");
            }

        }
        return map;
    }


    @ApiOperation("消防预警分级模型-电流")
    @PostMapping("/xf/currentAlarm")
    public Map getJtAlarm(@RequestBody WarningXfCurrentAlarmDto warningXfCurrentAlarmDto) {
        Map map = new HashMap();
        map.put("number",warningXfCurrentAlarmDto.getNumber());
        map.put("input",warningXfCurrentAlarmDto);
        Integer days =warningXfCurrentAlarmDto.getThreeDayTimes();
        Double duration = 0.0;
        if(warningXfCurrentAlarmDto.getDuration()!=null)
        {
            duration = warningXfCurrentAlarmDto.getDuration();
        }

        if(days == null)
        {
            map.put("msg","请输入正确的参数");
            return map;
        }

        if(days >= 6)
        {
            map.put("level","一级预警");
        }
        else if(days >= 4)
        {
            if(duration<1.0){
                map.put("level","二级预警");
            }
            else {
                map.put("level","一级预警");
            }
        }
        else if(days >= 2)
        {
            if(duration<1.0){
                map.put("level","三级预警");
            }
            else {
                map.put("level","二级预警");
            }
        }
        else
        {
            if(duration<1.0){
                map.put("level","四级预警");
            }
            else {
                map.put("level","三级预警");
            }

        }
        return map;
    }





     public static void main(String[] args) {
         Double v =1.0;
         Double v0 =20.0;
         Double v_v0 = v/v0;
         System.out.println(v_v0);
    }
}
